
//
//  TopBackgroundImage.m
//  AirQuality
//
//  Created by Mac on 16/1/22.
//  Copyright © 2016年 Po. All rights reserved.
//

#import "TopBackgroundImage.h"

@interface TopBackgroundImage ()

@property (weak, nonatomic) IBOutlet UILabel *todayTime;
@property (weak, nonatomic) IBOutlet UILabel *aqiValue;
@property (weak, nonatomic) IBOutlet UILabel *aqiRank;

@end

@implementation TopBackgroundImage


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        TopBackgroundImage * topImage = [[NSBundle mainBundle] loadNibNamed:@"TopBackgroundImage" owner:nil options:nil][0];
        topImage.frame = frame;
        self = topImage;
        NSString * time = [RJTools getTimeWithFormat:@"HH:mm  EEEE"];
        _todayTime.text = time;
    }
    return self;
}

- (void)setRank:(NSString *)rank
{
    _rank = rank;
    _aqiRank.text = rank;
   
}

- (void)setValue:(NSString *)value
{
    _value = value;
    _aqiValue.text = value;
    UIColor * color = [RJTools getNewColorWithAirNum:[value floatValue] type:@"AQI" alpha:1];
    _aqiRank.backgroundColor = color;
    _aqiRank.layer.cornerRadius = 5.0;
    _aqiRank.layer.masksToBounds = YES;
    _aqiRank.textColor = [UIColor whiteColor];
    NSInteger rank = [RJTools getRankWithType1:@"AQI" num1:[value floatValue]];
    NSString * ranktext = [self getAQIRank:rank];
    _aqiRank.text = ranktext;
}

- (NSString *)getAQIRank:(NSInteger)rank
{
    NSArray * arr = @[@"优",@"良",@"轻度污染",@"中度污染",@"重度污染",@"严重污染"];
    return arr[rank];
}

@end
